import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import Layout from '@/layout'

import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import excelRouter from './modules/excel'
import exampleRouter from './modules/example'
import permissionRouter from './modules/permission'
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index'),
      },
    ],
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true,
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true,
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true,
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    hidden: true,
    children: [
      {
        hidden: true,
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true },
      },
    ],
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: '个人信息', icon: 'user', noCache: true },
      },
    ],
  },
  {
    path: '/framecapability',
    component: Layout,
    name: 'framecapability',
    redirect: 'noRedirect',
    children: [
      componentsRouter,
      chartsRouter,
      tableRouter,
      excelRouter,
      exampleRouter,
      permissionRouter,
      {
        path: 'icons',
        component: () => import('@/views/_framecapability/icons/index'),
        name: 'Icons',
        meta: { title: '图标库', icon: 'icon', noCache: true },
      },
      {
        path: 'zip',
        component: () => import('@/views/_framecapability/zip/index'),
        name: 'ExportZip',
        meta: { title: 'zip压缩', icon: 'zip' },
      },

      {
        path: 'tab',
        component: () => import('@/views/_framecapability/tab/index'),
        name: 'Tab',
        meta: { title: 'Tab选项卡', icon: 'tab' },
      },
      {
        path: 'index',
        component: () => import('@/views/_framecapability/theme/index'),
        name: 'Theme',
        meta: { title: '主题', icon: 'theme' },
      },
      {
        path: 'clipboard',
        component: () => import('@/views/_framecapability/clipboard/index'),
        name: 'ClipboardDemo',
        meta: { title: '剪切板', icon: 'clipboard' },
      },
      {
        path: 'https://www.baidu.com',
        meta: { title: '外部链接跳转', icon: 'link' },
      },
      {
        path: '401',
        component: () => import('@/views/error-page/401'),
        name: 'Page401',
        meta: { title: 'err401', noCache: true, icon: '404' },
      },
      {
        path: '404',
        component: () => import('@/views/error-page/404'),
        name: 'Page404',
        meta: { title: 'err404', noCache: true, icon: '404' },
      },
      {
        path: 'log',
        component: () => import('@/views/_framecapability/error-log/index'),
        name: 'ErrorLog',
        meta: { title: '错误日志', icon: 'bug' },
      },
    ],
    meta: { title: '框架能力', icon: 'el-icon-s-grid' },
  },
]

// export const asyncRoutes = [
//   {
//     path: '/business-baseinfo',
//     component: Layout,
//     redirect: 'noRedirect',
//     name: 'businessBaseinfo',
//     meta: {
//       title: '档案信息',
//       icon: 'el-icon-s-order',
//     },
//     children: [
//       {
//         path: 'user',
//         component: () => import('@/views/_level2/index'),
//         redirect: 'noRedirect',
//         name: 'baseinfo-user',
//         children: [
//           {
//             path: 'page',
//             component: () => import('@/views/business-baseinfo/userinfo/index'),
//             name: 'userinfo',
//             meta: {
//               title: '人员档案',
//             },
//           },
//         ],
//       },
//     ],
//   },
// ]

const createRouter = () =>
  new Router({
    // mode: 'hash',
    mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  })
const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
